import { User } from '@app/database/schemas/user.schema';
import { Body, Controller, Post, Request, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { UserDto } from './dto/login.dto';

@ApiTags('前台台权限模块')
@ApiBearerAuth()
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @ApiOperation({ summary: '用户登录' })
  @UseGuards(AuthGuard('local'))
  @Post('login')
  async login(@Request() req, @Body() userDto: UserDto) {
    return this.authService.login(req.user);
  }

  @ApiOperation({ summary: '用户注册' })
  @Post('register')
  async register(@Body() user: User) {
    return this.authService.register(user);
  }
}
